#!/usr/bin/env bash
#
shopt -s extglob
# ——— 只在第一次 source 时定义 ROOT_DIR —— #
if [[ -z "${ROOT_DIR+x}" ]]; then
  readonly ROOT_DIR="$(pwd)"
fi

function envsetup()
{
    echo "OK!!! You need to execute the 'make' ..."
}

function make()
{
    if [ "$PWD" != "$ROOT_DIR" ]; then
      echo "错误：请在根目录 $ROOT_DIR 下执行此脚本，当前在 $PWD" >&2
      return
    fi
    mkdir -p build && cd build
    cmake ..
    command make
    cd $ROOT_DIR
}

function make-distclean() 
{
    if [ "$PWD" != "$ROOT_DIR" ]; then
      echo "错误：请在根目录 $ROOT_DIR 下执行此脚本，当前在 $PWD" >&2
      return
    fi
    rm $ROOT_DIR/build/* -rf
}
function run()
{
    if [ "$PWD" != "$ROOT_DIR" ]; then
      echo "错误：请在根目录 $ROOT_DIR 下执行此脚本，当前在 $PWD" >&2
      return
    fi
    $PWD/build/lwip_app
}
declare -f croot > /dev/null || envsetup 